#ifndef _DX8_FONT_H_
#define _DX8_FONT_H_

#include "font/font.h"
#include <D3D8.h>
#include <Wingdi.h>

namespace buffer
{
    class VertexBuffer;
}
#include "dx8_graphics.h"
#include "math/vec2.h"
class DX8Font : public Font
{
public:
                    DX8Font( const std::string& Name );
	virtual			~DX8Font();
	virtual void	Resize(const std::string& _Face, int Width, int Height, int Weight, unsigned long CharSet);
	virtual void	Render(	const std::wstring& Text,
							const math::Vec2& Pos,
							const math::Vec2& Size = math::Vec2(1.0f, 1.0f),
							unsigned int Flags = DT_WORDBREAK, 
							COLOR		Color = ColorRGBA(255, 255, 255),
							bool		Clip=false);

								
	virtual void			FlushSprite();
	virtual void			Flush();
	virtual bool			CustomInit() { return true; };
	virtual void			DeInit();
	bool					GlyphSupported(unsigned short GlyphID, void* pSet);


	virtual void			CacheGlyphs(bool	CopyRect);
	GlyphData*				GetFreeGlyph(unsigned short Glyph);
	virtual GlyphData*		GetGlyphIndex(unsigned short Glyph);

	//virtual void			RenderGlyphData(const math::Vec2& Pos, const math::Vec2& Size, COLOR Color, LineData* LineA, GlyphData**	GlyphA, int Lines, int Glyphs, unsigned int Flags, bool Draw);

	void					CacheGlyph(GlyphData* pGlyph);
	void					UpdateGlyph(GlyphData* pGlyph);
protected:
	virtual void			SetTexture();
	int						GetFontPixel(int x, int y);

	
	// the actual texture
    LPDIRECT3DTEXTURE8		m_pTexture;					// The d3d texture for this font
	HDC						m_hDC;						// handle to a context
	HBITMAP					m_hBMP;						// handle to the bitmap
	HFONT					m_hFont;					// create the font
	HFONT					m_hAltFont;					// create the font
    DWORD*					m_pBitmapBits;
	WORD*					m_DestSurf;
	bool					m_ToCopyRect;

	std::vector<GlyphData*>	m_pEmpty;
	int						m_CacheGlyphC;						// glyphs to cache this time

	int						m_QuadSize;

	// stats from last draw-call
	void*					m_pGlyphSet;
	void*					m_pAltGlyphSet;

private:
	int						m_TempX, m_TempY;
};

#endif // _DX8_FONT_H_